package com.punai.customer.controller;

import com.punai.common.annotation.Log;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.domain.TreeBo;
import com.punai.common.core.page.TableDataInfo;
import com.punai.common.enums.BusinessType;
import com.punai.customer.domain.CusLinkMechanicalStaCus;
import com.punai.customer.domain.vo.LinkCusStaVo;
import com.punai.customer.domain.vo.MechanicalStaCusVo;
import com.punai.customer.domain.vo.MechanicallVo;
import com.punai.customer.service.ICusLinkMechanicalStaCusService;
import com.punai.customer.service.ICusMechanicalStaChapterService;
import com.punai.customer.service.ICusMechanicalStaItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 标准机械与客户机械的对应Controller
 * 
 * @author zxw_
 * @date 2023-02-02
 */
@RestController
@RequestMapping("/cus/linkMechanicalStaCus")
public class CusLinkMechanicalStaCusController extends BaseController
{
    @Autowired
    private ICusLinkMechanicalStaCusService cusLinkMechanicalStaCusService;
    @Autowired
    private ICusMechanicalStaChapterService cusMechanicalStaChapterService;
    @Autowired
    private ICusMechanicalStaItemService cusMechanicalStaItemService;

    /**
     * 新增标准机械与客户机械的对应
     */
    @PreAuthorize("@ss.hasPermi('cus:linkStaCusJX:add')")
    @Log(title = "标准机械与客户机械的对应", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MechanicalStaCusVo vo)
    {
        return toAjax(cusLinkMechanicalStaCusService.insertLink(vo));
    }

    /**
     * 删除标准机械与客户机械的对应
     */
    @PreAuthorize("@ss.hasPermi('cus:linkStaCusJx:remove')")
    @Log(title = "标准机械与客户机械的对应", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(cusLinkMechanicalStaCusService.deleteCusLinkMechanicalStaCusById(id));
    }


    // 拉取存在的关联关系
    @PreAuthorize("@ss.hasPermi('cus:linkStaCus:list')")
    @GetMapping("/selectUsedLink")
    public TableDataInfo selectUsedLink(LinkCusStaVo vo)
    {
        startPage();
        List<CusLinkMechanicalStaCus> list = cusLinkMechanicalStaCusService.selectUsedLink(vo);
        return getDataTable(list);
    }


    // 拉取标准费用项
    @PreAuthorize("@ss.hasPermi('cus:linkStaCus:list')")
    @GetMapping("/selectStaMechanicalTree")
    public AjaxResult selectStaMechanicalTree()
    {
        List<TreeBo> treeBos = cusMechanicalStaChapterService.selectTreeData();
        return AjaxResult.success(treeBos);
    }
    // 拉取标准费用项
    @PreAuthorize("@ss.hasPermi('cus:linkStaCus:list')")
    @GetMapping("/selectStaMechanicalList")
    public TableDataInfo selectStaMaterialList(MechanicallVo vo)
    {
        return cusMechanicalStaItemService.selectListData(vo);
    }

    // 拉取客户费用项
    @PreAuthorize("@ss.hasPermi('cus:linkStaCus:list')")
    @GetMapping("/selectCusMechanicalList")
    public TableDataInfo selectCusMaterialList(MechanicallVo vo)
    {
        return cusLinkMechanicalStaCusService.selectMaterialList(vo);
    }
}
